#ifndef RTREACTORTHREADPROXY_H
#define RTREACTORTHREADPROXY_H

#include "RtReactorInterface.h"
#include "RtThreadProxyManager.h"

class CRtReactorThreadProxy : public IRtReactor, public CRtThreadProxyBase
{
public:
	CRtReactorThreadProxy(IRtReactor *aReactor, CRtThreadManager::TType aType);
	virtual ~CRtReactorThreadProxy();

	// interface IRtReactor
	virtual RtResult Open();

	virtual RtResult RegisterHandler(
		IRtEventHandler *aEh,
		IRtEventHandler::MASK aMask);

	virtual RtResult RemoveHandler(
		IRtEventHandler *aEh,
		IRtEventHandler::MASK aMask = IRtEventHandler::ALL_EVENTS_MASK);

	virtual RtResult NotifyHandler(
		IRtEventHandler *aEh,
		IRtEventHandler::MASK aMask);

	virtual RtResult RunEventLoop();

	virtual RtResult StopEventLoop();

	virtual RtResult Close();

	// interface IRtTimerQueue
	RtResult ScheduleTimer(IRtTimerHandler *aTh, 
					  LPVOID aArg,
					  const CRtTimeValue &aInterval,
					  DWORD aCount);
	virtual RtResult CancelTimer(IRtTimerHandler *aTh);

	// interface IRtEventQueue
	virtual RtResult PostEvent(IRtEvent *aEvent);

	virtual RtResult SendEvent(IRtEvent *aEvent);

private:
	IRtReactor *m_pReactor;

	class CEventRegisterHandler : public IRtEvent
	{
	public:
		CEventRegisterHandler(IRtReactor *aReactor, IRtEventHandler *aEh, 
			IRtEventHandler::MASK aMask)
			: m_pReactor(aReactor)
			, m_pEh(aEh)
			, m_Mask(aMask)
		{
		}

		virtual ~CEventRegisterHandler();

		virtual RtResult OnEventFire();

	private:
		IRtReactor *m_pReactor;
		IRtEventHandler *m_pEh;
		IRtEventHandler::MASK m_Mask;
	};

	class CEventRemoveHandler : public IRtEvent
	{
	public:
		CEventRemoveHandler(IRtReactor *aReactor, IRtEventHandler *aEh, 
			IRtEventHandler::MASK aMask)
			: m_pReactor(aReactor)
			, m_pEh(aEh)
			, m_Mask(aMask)
		{
		}

		virtual ~CEventRemoveHandler();

		virtual RtResult OnEventFire();

	private:
		IRtReactor *m_pReactor;
		IRtEventHandler *m_pEh;
		IRtEventHandler::MASK m_Mask;
	};
};

#endif // !RTREACTORTHREADPROXY_H
